#!/bin/bash

function usage() {
    echo "$( basename $0 ) [-1 | -2 | -a | -h]"
    echo "    Stop eb qemu"
    echo "    参数说明:"
    echo "        -1: 停止qemu实例1, 默认"
    echo "        -2: 停止qemu实例2"
    echo "        -a: 停止qemu1和qemu2"
    echo "        -h: 打印帮助信息"
    exit 1
}

set -e 

while getopts ":12ah" args
do
    case "$args" in
        1)
            instances=(1)
            ;;
        2)
            instances=(2)
            ;;
        a)
            instances=(1 2)
            ;;
        h)
            usage
            ;;
        *)
            usage
            ;;
    esac
done

if [ 0 -eq ${#instances[@]} ]
then
    instances=(1)
fi

for i in "${instances[@]}"
do
    echo ara-cli RunQemu --stop $i 
    ara-cli RunQemu --stop $i 
done
